/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package systole.view.averages;

import java.awt.Color;
import systole.exceptions.ExceptionDAO;
import systole.persistence.FacadeDB;
import systole.view.utils.ErrorDialog;

/**
 *
 * @author jmj
 */
public class ControllerAverageView {

    private JDialogAverages averages;

    /**
     * 
     */
    public ControllerAverageView() {
        this.averages = null;
    }

    /**
     * Method to close form
     */
    public void closeForm() {
        this.averages.setVisible(false);
        this.averages.dispose();
    }

    /**
     * @param parent
     */
    public void showForm(java.awt.Frame parent) {
        try {
            this.averages = new JDialogAverages(parent, this);
            this.averages.setLocationRelativeTo(parent);
            this.averages.getjXTableAverages().setModel(new AveragesTableModel(FacadeDB.getInstance().getAveragesBroker().getAverages()));

            this.averages.getjXTableAverages().setSelectionBackground(Color.blue);
            this.averages.getjXTableAverages().packAll();
            this.averages.setVisible(true);
        } catch (ExceptionDAO ex) {
            ErrorDialog.showError(parent, ex.getMessage());
            FacadeDB.getInstance().refreshSession();
            this.averages.dispose();
        }
    }
}
